package com.zz.service.iml;

import com.zz.dao.NurseDao;
import com.zz.dto.NurseResult;
import com.zz.pojo.Nurse;
import com.zz.service.NurseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Copyright Zz
 * FileName: NurseServiceIml
 * Author:   Zz
 * Date:     2023/6/1017:57
 * Description:护士表业务层实现类
 * hISTORY:
 * <author>  <time>     <version>    <desc>
 * 作者姓名   修改时间       版本号       描述
 */
@Service
@Transactional
public class NurseServiceIml implements NurseService {
    @Autowired
    private NurseDao nurseDao;

    @Override
    public NurseResult queryNurseList(Map<String, Integer> map) {
        NurseResult nurseResult=new NurseResult();
        List<Nurse> list=nurseDao.queryNurseList(map);
        nurseResult.setNurseData(list);
        nurseResult.setCurrentPageSize(list.size());
        int countNurse=nurseDao.countNurse();
        nurseResult.setPageCount((int) Math.ceil(countNurse/(double)Integer.parseInt(String.valueOf(map.get("pageSize")))));
        return nurseResult;
    }

    @Override
    public NurseResult queryNurseByKey(Map<String, Object> map) {
        NurseResult nurseResult=new NurseResult();
        List<Nurse> list=nurseDao.queryNurseByKey(map);
        nurseResult.setNurseData(list);
        nurseResult.setCurrentPageSize(list.size());
        int countNurse=nurseDao.countNurseBykey(map);
        nurseResult.setPageCount((int) Math.ceil(countNurse/(double)Integer.parseInt(String.valueOf(map.get("pageSize")))));
        return nurseResult;
    }

    @Override
    public int insertNurse(Nurse nurse) {
        if (nurseDao.queryNurseByID(nurse.getNurseId())!=null)
            return 2;
        else return nurseDao.insertNurse(nurse);
    }

    @Override
    public int updateNurse(Nurse nurse) {
        return nurseDao.updateNurse(nurse);
    }

    @Override
    public int deleteNurse(String ID) {
        return nurseDao.deleteNurse(ID);
    }
}
